﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SHeliSuspend : SFuncBase
{
    public float MaxSpeed=10;

    float gravityDir;
    public override void SStart()
    {
        base.SStart();
        gravityDir = GetComponent<SComBody>().MeshRotate*90-90;
    }
    public override void SetRigid(Rigidbody2D r)
    {
        base.SetRigid(r);
        r.freezeRotation = true;
        r.gravityScale = 0;
    }
    public override void ClearRigid()
    {
        Rigid.freezeRotation = false;
        Rigid.gravityScale = 1;
        base.ClearRigid();

        
    }
    public override void SFixedUpdate()
    {
        base.SFixedUpdate();
        this.AddForceAtWordPosition(transform.position, gravityDir, Physics2D.gravity.magnitude);
    }
    public override void LocalKeyOn()
    {
        base.LocalKeyOn();
        var v = Rigid.velocity;
        v = Vector3.Project(v, this.transform.right);
        Rigid.velocity = v+(Vector2)this.transform.up * MaxSpeed;
    }
}